package cn.lkp.mall.member.web;


import cn.lkp.common.utils.R;
import cn.lkp.mall.member.feign.OrderFeign;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
public class MemberWebController {
    @Autowired
    OrderFeign orderFeign;
    //视频defaultValue = "1" gulimall中为"0"
    @GetMapping(value = "/memberOrder.html",produces = "text/html")
    public String memberOrderPage(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
                                  Model model, HttpServletRequest request){
        //获取到支付宝给我们转来的所有请求数据
        //request,验证签名

        //查出当前登录用户的所有订单列表数据
        Map<String,Object> page = new HashMap<>();
        page.put("page",pageNum.toString());

        //远程查询订单服务订单数据
        R orderInfo = orderFeign.listWithItem(page);
        //使用了分页工具类，打印出json格式的响应数据，使用json工具类显示数据结构层级，完成页面渲染
        System.out.println(JSON.toJSONString(orderInfo));
        model.addAttribute("orders",orderInfo);
        return "orderList";
    }
}
